package com.googlecode.animator.data.objects3d
{
	import com.googlecode.animator.data.IValueObject;
	import com.googlecode.animator.data.materials.BitmapFileMaterialVO;
	import com.googlecode.animator.data.materials.ColorMaterialVO;
	import com.googlecode.animator.data.materials.MaterialVO;
	import com.googlecode.animator.data.materials.MovieMaterialVO;
	import com.googlecode.animator.data.materials.VideoStreamMaterialVO;
	
	public class PlaneVO extends SingleMaterialObject3DVO
	{
		
		public static const TYPE:String = "Plane";
		
		public static const FRONT_FACE:String = "front";
		
		public var width:Number = 500;
		
		public var height:Number = 500;
		
		public var segmentsW:uint = 4;
		
		public var segmentsH:uint = 4;
		
		public var billboard:Boolean = false;
		
		/* public var material:MaterialVO; */
		
		public function PlaneVO()
		{
			label = "Default Plane";
		}
		
		override public function clone(src:* = null):IValueObject
		{
			var clone:IValueObject = super.clone(new PlaneVO());
			
			(clone as PlaneVO).width = this.width;
			(clone as PlaneVO).height = this.height;
			(clone as PlaneVO).segmentsH = this.segmentsH;
			(clone as PlaneVO).segmentsW = this.segmentsW;
			(clone as PlaneVO).billboard = this.billboard;
			/* (clone as PlaneVO).material = this.material.clone() as MaterialVO; */
			
			return (clone as PlaneVO);
		}
		
		override public function toXML(src:XML = null):XML
		{
			var xml:XML = super.toXML(new XML(<{TYPE} name={this.name} label={this.label}></{TYPE}>));
			
			xml.appendChild(<width>{int(this.width * this.scaleX)}</width>);
			xml.appendChild(<height>{int(this.height * this.scaleY)}</height>);
			xml.appendChild(<billboard>{this.billboard}</billboard>);
			/* xml.appendChild(<material>{this.material.toXML()}</material>); */

			return xml;
		}
		
		override public function fromXML(src:XML):void
		{
			super.fromXML(src);

			this.width = src.width;
			this.height = src.height;
			this.billboard = src.billboard == "true" ? true : false;
			/* var newMat:MaterialVO;

			if(src.material.*.name() == ColorMaterialVO.TYPE)
			{
				newMat = new ColorMaterialVO();
				(newMat as ColorMaterialVO).fillAlpha = src.material.*.fillAlpha;
				(newMat as ColorMaterialVO).fillColor = src.material.*.fillColor;
				 
			}
			
			if(src.material.*.name() == MovieMaterialVO.TYPE)
			{
				newMat = new MovieMaterialVO();
				(newMat as MovieMaterialVO).filePath = src.material.*.filePath;			
				(newMat as MovieMaterialVO).isRelative = src.material.*.isRelative;
			}
			
			if(src.material.*.name() == BitmapFileMaterialVO.TYPE)
			{
				newMat = new BitmapFileMaterialVO();
				(newMat as BitmapFileMaterialVO).filePath = src.material.*.filePath;
				(newMat as BitmapFileMaterialVO).isRelative = src.material.*.isRelative;

			}
			
			if(src.material.*.name() == VideoStreamMaterialVO.TYPE)
			{
				newMat = new VideoStreamMaterialVO();
				(newMat as VideoStreamMaterialVO).filePath = src.material.*.filePath;
				(newMat as VideoStreamMaterialVO).isRelative = src.material.*.isRelative;
				(newMat as VideoStreamMaterialVO).width = src.material.*.width;
				(newMat as VideoStreamMaterialVO).height = src.material.*.height;

			}
			
			this.material = newMat; */
		}
	}
}